home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Programmer Disk
/
The Programmer Disk (Microforum).iso
/
xpro
/
c2
/
pro4
/
findwrld.c
< prev
next >
Wrap
Text File
|
1986-05-28
|
1KB
|
57 lines
/* «RM120»«PL99999»«TS4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76» */
#include <stdio.h>
#define EXTERN extern
#include <typedef.h>
void FindWorld(i,A,NPoints,ScaleX,ScaleY)
int i, NPoints;
double *A, ScaleX, ScaleY;
{
extern double fabs();
double XMax,YMax,XMin,YMin;
int k;
double xmid, ymid, xdiff, ydiff;
NPoints = iabs(NPoints);
if (NPoints < 2) {
error(7,4);
return;
}
if (!((1 <= i) && (i <= MaxWorldsGlb))) {
error(7,2);
return;
}
XMax = A[0];
YMax = A[1];
XMin = XMax;
YMin = YMax;
for (k = 2; k < 2 * NPoints; k++) { /* NB. k incremented in code */
if (A[k] > XMax)
XMax = A[k];
else if (A[k] < XMin)
XMin = A[k];
if (A[++k] > YMax)
YMax = A[k];
else if (A[k] < YMin)
YMin = A[k];
}
ScaleX = fabs(ScaleX);
ScaleY = fabs(ScaleY);
xdiff = XMax - XMin;
xmid = .5 * (XMin + XMax);
XMax = xmid + ScaleX * .5 * xdiff;
XMin = xmid - ScaleX * .5 * xdiff;
ydiff = YMax - YMin;
ymid = .5 * (YMin + YMax);
YMax = ymid + ScaleY * .5 * ydiff;
YMin = ymid - ScaleY * .5 * ydiff;
DefineWorld(i,XMin,YMin,XMax,YMax);
SelectWorld(i);
}